package com.onenine.app.view;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.AttributeSet;
import android.widget.RelativeLayout;

import com.onenine.app.R;
import com.onenine.chat.listener.OnClickEditTextListener;
import com.onenine.chat.listener.OnMenuClickListener;
import com.onenine.chat.message.MessageList;
import com.onenine.chat.message.MsgListAdapter;
import com.onenine.chat.view.AudioRecordButton;
import com.onenine.chat.view.ChatInputView;


public class ChatView extends RelativeLayout {

    private MessageList mMsgList;
    private ChatInputView mChatInput;
    private AudioRecordButton mRecordVoiceBtn;

    public ChatView(Context context) {
        super(context);
    }

    public ChatView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ChatView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void initModule() {
        mMsgList = findViewById(R.id.msg_list);
        mChatInput = findViewById(R.id.chat_input);
        mChatInput.setAudioFormat(true);
        mRecordVoiceBtn = mChatInput.getRecordVoiceButton();
        mRecordVoiceBtn.setAudioFormat(true);
        mMsgList.setHasFixedSize(true);
    }

    public void setMenuClickListener(OnMenuClickListener listener) {
        mChatInput.setMenuClickListener(listener);
    }

    public void setAdapter(MsgListAdapter adapter) {
        mMsgList.setAdapter(adapter);
    }

    public void setLayoutManager(RecyclerView.LayoutManager layoutManager) {
        mMsgList.setLayoutManager(layoutManager);
    }

    public void setCameraCaptureFile(String path, String fileName) {
        mChatInput.setCameraCaptureFile(path, fileName);
    }

    public void setRecordVoiceListener(AudioRecordButton.AudioFinishRecorderListener listener) {
        mChatInput.setRecordVoiceListener(listener);
    }

    public void setOnTouchListener(OnTouchListener listener) {
        mMsgList.setOnTouchListener(listener);
    }

    public void setOnTouchEditTextListener(OnClickEditTextListener listener) {
        mChatInput.setOnClickEditTextListener(listener);
    }

    @Override
    public boolean performClick() {
        super.performClick();
        return true;
    }

    public ChatInputView getChatInputView() {
        return mChatInput;
    }

    public MessageList getMessageListView() {
        return mMsgList;
    }

    public AudioRecordButton getRecordVoiceBtn() {
        return mRecordVoiceBtn;
    }

    public void setPrivateOrGroupExpandContent(int type, String targetId) {
        mChatInput.setPrivateOrGroupExpandContent(type, targetId);
    }

    public void showGiftBoard() {
        mChatInput.showGiftBoard();
    }

    public void setChatInputBackgroundColor(int color) {
        mChatInput.setLayoutBackground(color);
    }

    public void setChatInputTopBottomDividerLineVisible(boolean visible) {
        mChatInput.setTopBottomHorizontalDividerVisible(visible);
    }

    public void setChatInputEditBackgroundResource(int resId) {
        mChatInput.setEditBackgroundResource(resId);
    }

    public void setChatInputEditTextColor(int color) {
        mChatInput.setEditTextColor(color);
    }

    public void clearAudioStageListener() {
        mRecordVoiceBtn.clearAudioStageListener();
    }

    public boolean canScrollFirstVertically() {
        return mMsgList.canScrollVertically(1);
    }

}
